import { Component, OnInit, ViewChild } from '@angular/core';

import { Service } from '../../../server/server';
import { InitService } from '../../../public/serve/init/init.service';
import { HintsService } from '../../../public/serve/hints/hints.service';
import { CudTableService } from '../../../public/serve/cud-table/cud-table.service';
// import { RemoveTableService } from '../../../public/serve/remove-table/remove-table.service';

import { appProductUrl } from '../../product.url';
import { checktask } from '../../product.data';
// import { taskAddEimt } from "../product-task-list";

import { ProductIndexingTaskAuditTableComponent } from './table/product-indexing-task-audit-table.component';
import { ActivatedRoute, Params } from '@angular/router';
declare var $:any;
@Component({
    selector: 'app-product-indexing-task-audit',
    templateUrl: './product-indexing-task-audit.component.html',
    styleUrls: ['./product-indexing-task-audit.component.css']
})
export class ProductIndexingTaskAuditComponent implements OnInit {
    status: string = '';
    queryCriteria: string = '';
    @ViewChild("table") table : ProductIndexingTaskAuditTableComponent; 
    isActive = this.server.isActive;

    taskType: any = 0;
    right: any = {
        "taskPermissionAudit":{},
        "productAudit": {},
        "internalAudit": {},
        "themeTaskAudit": {}
    };

    constructor(
        public initService: InitService,
        // public removeTableService: RemoveTableService,
        public request: CudTableService,
        public server: Service,
        private hintsService: HintsService,
        private activatedRoute: ActivatedRoute,
        ) { 
            this.right = $.extend(this.right, server.getRight());
    }

    ngOnInit() {
        this.activatedRoute.queryParams.subscribe((p: Params) => {
            this.taskType = String(p['taskType']);
        });

        this.activatedRoute.url.subscribe(r => {
            //权限
            if(this.taskType == '1'){
                //内文任务
                this.right['taskPermissionAudit'] = this.right['internalAudit'];
            }else if(this.taskType == '0'){
                //产品任务
                this.right['taskPermissionAudit'] = this.right['productAudit'];
            }else if(this.taskType == '2'){
                //主题词任务
                this.right['taskPermissionAudit'] = this.right['themeTaskAudit'];
            }
        })

        this.server.eventEmit.subscribe((value: any) => {
            this.isActive = value;
        });
    }

    /**
      * 分页
      * @param pagination 
      */
    _pagination(pagination: Array<any>) {
        checktask.pagination.pageNo = pagination[0].pageNumber;
        checktask.pagination.pageSize = pagination[0].pageSize;
        checktask.pagination.naturalNum = (checktask.pagination.pageNo - 1) * checktask.pagination.pageSize;
        this.table.getTabList();
    }

    //审核状态改变筛选
    getChange(status) {
        checktask.retrieval.checkStatus = status;
        this._retrieval('');
    }

    /**
     * 搜索
     * @param val
     */
    _retrieval(val: string) {
        if(val) {
            checktask.retrieval.queryCriteria = val.trim();
            this.queryCriteria = val.trim();
        }
        this.table.getTabList();
    }

    // //通过
    // _enable() {
    //     let taskIds = this.removeTableService._AllId('taskId');
    //     this.removeTableService._clearId('taskId');
    //     taskAddEimt.emit({ 'data': 'pass' });
    //     this.setTaskStatus(200, taskIds);
    //     this.table.getTabList();
    //     console.log('通过', taskIds);
    // }

    // //不通过
    // _disable() {
    //     let taskIds = this.removeTableService._AllId('taskId');
    //     this.removeTableService._clearId('taskId');
    //     taskAddEimt.emit({ 'data': 'unpass' });
    //     this.setTaskStatus(-1, taskIds);
    //     this.table.getTabList();
    //     console.log('不通过', taskIds);
    // }

    // setTaskStatus(status, taskIds) {
        // let params = {
        //     status: status,
        //     taskIds: taskIds
        // };
        // this.request.postRequest(appProductUrl.getTasksList, params).then((res: any) => {
        //     if (res.result_code === '0000') {
               
        //     } 
        //     this.hintsService.messages(res.message, res.result_code);
  
        //     return;
        // }).catch((err: any) => {
        //     this.hintsService.messages("error", "error");
        //     return;
        // });
    // }
}
